var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
var filter = require('../../../services/filter.js');

Page(filter.identityFilter({
  data:{
    orderList: [],
    page: 1,
    size: 10,
    totalPages: 1
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
    this.getOrderList();
  },
  getOrderList(){
    let that = this;
    util.request(api.OrderList, { page: that.data.page, size: that.data.size }).then(function (res) {
      if (res.errno === 0) {
        //console.log(res.data);
        that.setData({
          orderList: that.data.orderList.concat(res.data.data),
          totalPages: res.data.totalPages
        });
        wx.hideLoading();
      }
    });
  },
  payOrder(){
    wx.redirectTo({
      url: '/pages/pay/pay',
    })
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示

    // wx.showLoading({
    //   title: '加载中...',
    //   success: function () {

    //   }
    // });
    
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  /**
   * 下拉翻页
   */
  onReachBottom() {
    if (this.data.totalPages > this.data.page) {
      this.setData({
        page: this.data.page + 1
      });
    } else {
      return false;
    }

    this.getOrderList();
  },
}))